﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTGroup_ZheJiang.Models;
using DTGroup_ZheJiang.IDAL;
using System.Data.OracleClient;
using System.Configuration;
using System.Data;

namespace DTGroup_ZheJiang.OracleDataAccess
{
    public class UserDao:IUser
    {
        public string connString = ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        public User Login(string userAccount, string password)
        {
            User u = new User();
            string sqlText = " SELECT * FROM Users where UserName = '" + userAccount + "' and PASSWORD = '" + password + "' and Status != 2 ";
            using (OracleConnection conn = new OracleConnection(connString))
            {
                conn.Open();
                using (OracleCommand cmd=conn.CreateCommand())
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sqlText;
                    cmd.CommandTimeout = 10 * 60 * 60;
                    using (OracleDataReader sdr=cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            //u.UserID = Convert.ToInt32(sdr["USERID"]);
                            //u.RealName = sdr["REALNAME"].ToString();
                            u.UserName = sdr["USERNAME"].ToString();
                            u.Password = sdr["PASSWORD"].ToString();
                            //u.Email = sdr["EMAIL"].ToString();
                            //u.Company = sdr["COMPANY"].ToString();
                            //u.Status = Convert.ToInt32(sdr["STATUS"]);
                            //u.IsAdmin = Convert.ToInt32(sdr["ISADMIN"]) == 1;
                            //u.CreateDatetime = Convert.ToDateTime(sdr["CREATEDATETIME"]);
                            //u.RoleID = Convert.ToInt32(sdr["ROLEID"]);
                            //u.BelongPosition = sdr["BELONGPOSITION"].ToString();
                            //u.Name = sdr["NAME"].ToString();
                            //u.Telephone = sdr["TELEPHONE"].ToString();
                        }
                    }
                }
            }
            return u;
        }
    }
}
